<!--
 * @Date: 2019-11-06 10:43:33
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-03-28 14:50:20
 -->
<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive">
      </router-view>
    </keep-alive>

    <router-view v-if="!$route.meta.keepAlive">
    </router-view>
  </div>
</template>

<script>
  export default {
    name: 'app',
    data() {
      return {
        exitAppTicker: 0
      }
    },
    mounted() {
      // this.backbutton()
    },
    methods: {
      backbutton() {
        let _this = this
        document.addEventListener("deviceready", function() {
          document.addEventListener("backbutton", function() {
            if (_this.isHomePage()) {
              if (_this.exitAppTicker == 0) {
                _this.exitAppTicker++
                _this.$toast('再点一次退出应用')
                setTimeout(function () {
                  _this.exitAppTicker = 0
                }, 2000)
              } else if (_this.exitAppTicker == 1) {
                localStorage.removeItem('userInfo')
                navigator.app.exitApp() //退出app
              }
            } else {
              const pName = _this.$route.name.toString()
              if (pName == 'workstation' || pName == 'mine') {
                _this.$router.push('homePage')
              } 
              else {
                window.history.back()
              }
            }
          }, false)
        },false)
      },
      isHomePage() {
        const pathName = this.$route.name.toString()
        if (pathName == 'homePage' || pathName == 'login') {
          return true
        }
        return false
      }
    }
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
  }

  p {
    margin: 0;
  }

  ::-webkit-scrollbar {
    display: none;
  }
  .van-nav-bar__text:active {
    background-color:transparent !important;
  }
</style>